package demo7;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.net.Socket;
@Component
@PropertySource("classpath:config.properties")
public class cilent
{
    private String url;
    private int  port;
    private Socket s;

    public String getUrl() {
        return url;
    }
    @Value("${server.url}")
    public void setUrl(String url) {
        this.url = url;
    }

    public int getPort() {
        return port;
    }
    @Value("${server.port}")
    public void setPort(int port) {
        this.port = port;
    }
    @PostConstruct
    public void init()
    {
        try {
            s=new Socket(url,port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @PreDestroy
    public void close()
    {
        try {
            s.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
